<?php
	class Tk_categorys extends CI_Model{

		function __construct(){
			parent::__construct();
		}

		function get_top_categorys(){
			$sql = "SELECT * FROM {$this->db->dbprefix}tk_categorys where school_id = 0 ORDER BY id DESC";
			$result = $this->db->query($sql)->result_array();
			return $result;
		}

		function get_tk_category_list($limit = 0, $offset = 10, $conditions  = array()){
			$where = "1 = 1 AND school_id = 0";
			if($conditions){
				if(!empty($conditions['name'])){
					$where .= " AND name LIKE '%{$conditions['name']}%'";
				}
			}
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}tk_categorys WHERE $where ORDER BY id DESC ";
			if($limit > 0 || $offset > 0){
				$sql .= "LIMIT $limit, $offset";
			}
			$result = $this->db->query($sql)->result_array();
			$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
			return array("count" => $row_num['row_num'], "result" => $result);
		}

	}
